package com.k.base.jdk.thread.runable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author k
 */
public class RunnableTest {
    public static void main(String[] args) {
        new Thread(new MyThread("TOM")).start();
        new Thread(new MyRunnable("jim")).start();
        new Thread(new FutureTask<>(new MyCallable("kate"))).start();
    }

    static class MyRunnable implements Runnable{
        private String param;
        MyRunnable(String param){
            this.param = param;
        }
        @Override
        public void run() {
            System.out.println("通过 Runnable 创建线程"+ param);
        }
    }

    static class MyThread extends Thread{
        private String param;
        MyThread(String param){
            this.param = param;
        }
        @Override
        public void run() {
            System.out.println("通过 Thread 创建线程"+ param);
        }
    }

    static class MyCallable implements Callable<String>{
        private String param;
        MyCallable(String param){
            this.param = param;
        }
        @Override
        public String call() throws Exception {
            System.out.println("通过 Callable 创建线程"+ param);
            return null;
        }
    }
}
